﻿

var common = {
    datetimeFormatter: function (value) {
        if (value == undefined || value == "") {
            return "";
        }

        if (!isNaN(Date.parse(value))) {
            dateValue = new Date(Date.parse(value));
        } else if (value.indexOf('Date') > -1) {
            value = value.substr(1, value.length - 2);
            var obj = eval('(' + "{Date: new " + value + "}" + ')');
            var dateValue = obj["Date"];
            if (dateValue.getFullYear() < 1900) {
                return "";
            }
        }
        return dateValue.format("yyyy-MM-dd hh:mm:ss");
    },

    dateFormatter: function (value) {
        var dateValue;
        if (value == undefined || value == "") {
            return "";
        }
        if (!isNaN(Date.parse(value))) {
            dateValue = new Date(Date.parse(value));
        } else if (value.indexOf('Date') > -1) {
            value = value.substr(1, value.length - 2);
            var obj = eval('(' + "{Date: new " + value + "}" + ')');
            dateValue = obj["Date"];
            if (dateValue.getFullYear() < 1900) {
                return "";
            }
        }


        return dateValue.format("yyyy-MM-dd");
    },
    post: function (url, postData, callback) {
        $.ajax({
            type: 'Post',
            dataType: 'json',
            url: url,
            data: JSON.stringify(postData),
            contentType: 'application/json; charset=utf-8',
            async: false,
            success: function (data) {
                var icon = 'error';
                if (data.Result) {
                    var icon = 'info';
                    if (callback) {
                        callback(true);
                    }
                } else {
                    if (callback) {
                        callback(false);
                    }
                }
                top.showAlert(data.Message, icon);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                callback(false);
                top.showAlert(jqXHR.responseText, 'error');
            }
        });
    }
};